<template>
  <div class="bar-container">
    <div class="legend">
      <div class="list" v-for="item in legendList" :key="item.id">
        <div class="border" :style="{ background: item.color }"></div>
        <div class="title">{{ item.title }}</div>
      </div>
    </div>
    <div class="banner-container">
      <div class="banner-list" v-for="item in bannerList" :key="item.id">
        <div class="bar">
          <div
            class="list"
            :class="{ list_hidden: el.amount / max === 0 }"
            v-for="(el, elIndex) in item.y"
            :key="elIndex"
            :style="{
              height: `${(el.amount / max) * 100}%`,
            }"
          >
            <div class="top-txt" v-if="elIndex === 0"></div>
          </div>
        </div>
        <div class="title">{{ item.x }}</div>
        <div class="tootip">
          <div class="tootip-title">{{ item.x }}：{{ item.total }}万元</div>
          <div class="tootip-list" v-for="list in item.y" :key="list.pName">
            <div class="tootip-border"></div>
            <div class="tootip-label">{{ list.pName }}</div>
            <div class="tootip-value">{{ list.amount }}</div>
            <div class="tootip-unit">万元</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      legendList: [
        { title: "分公司账户", color: "rgba(24, 144, 255, 1)", id: 1 },
        { title: "电子承兑账户", color: "rgba(83, 237, 255, 1)", id: 2 },
        { title: "农民工专户", color: "rgba(31, 197, 87, 1)", id: 3 },
        { title: "第三方账户", color: "rgba(246, 197, 22, 1)", id: 4 },
      ],
    };
  },
  props: {
    bannerList: {
      default: () => [],
      type: Array,
    },
    max: {
      default: 0,
      type: String | Number,
    },
  },

  methods: {},
};
</script>

<style scoped lang="scss">
@import "@/views/report_form_dark/styles/fn.scss";

.bar-container {
  width: 100%;
  height: 100%;

  .legend {
    width: 100%;
    height: vh(45);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;

    .list {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;
      margin: 0 vw(8);
      cursor: pointer;
      user-select: none;

      .border {
        width: vw(8);
        height: vw(8);
        border-radius: 50%;
        margin-right: vw(4);
      }

      .title {
        font-size: vw(12);
        font-family: Microsoft YaHei UI;
        font-weight: 400;
        color: #8fc7ff;
        opacity: 0.4;
      }
    }
  }

  .banner-container {
    width: 100%;
    height: calc(100% - #{vh(45)});
    display: flex;
    flex-direction: row;

    .banner-list {
      width: calc(100% / 7);
      height: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: flex-end;
      position: relative;

      &:hover {
        .tootip {
          display: block;
        }
      }

      .tootip {
        display: none;
        position: absolute;
        top: vh(-20);
        z-index: 9;
        background: rgba(0, 51, 128, 0.88);
        border: 1px solid #004fc5;
        border-radius: 2px;
        padding: vw(6) vw(8);
        width: max-content;
        opacity: 1;

        .tootip-title {
          min-width: 100%;
          font-size: vw(12);
          font-family: Microsoft YaHei UI;
          font-weight: bold;
          line-height: vh(15);
          color: #8fc7ff;
          display: flex;
          flex-direction: row;
          white-space: nowrap;
        }

        .tootip-list {
          display: flex;
          flex-direction: row;
          align-items: center;
          margin: vh(10) 0;

          .tootip-border {
            width: vw(8);
            height: vw(8);
            border: 1px solid #ffffff;
            border-radius: 50%;
          }

          &:nth-child(2) {
            .tootip-border {
              background: #1890ff;
            }
          }
          &:nth-child(3) {
            .tootip-border {
              background: rgba(83, 237, 255, 1);
            }
          }
          &:nth-child(4) {
            .tootip-border {
              background: rgba(31, 197, 87, 1);
            }
          }
          &:nth-child(5) {
            .tootip-border {
              background: rgba(246, 197, 22, 1);
            }
          }

          .tootip-label {
            font-size: vw(12);
            font-family: Microsoft YaHei UI;
            font-weight: 400;
            color: #8fc7ff;
            opacity: 0.6;
            margin: 0 vw(20) 0 vw(4);
          }

          .tootip-value {
            font-size: vw(12);
            font-family: Microsoft YaHei UI;
            font-weight: 400;
            color: #8fc7ff;
            opacity: 0.6;
          }

          .tootip-unit {
            font-size: vw(12);
            font-family: Microsoft YaHei UI;
            font-weight: 400;
            color: #8fc7ff;
            opacity: 0.6;
          }
        }
      }

      &:nth-child(6) {
        .tootip {
          right: 0;
        }
      }

      &:nth-child(7) {
        .tootip {
          right: 0;
        }
      }

      .top-txt {
        position: absolute;
        top: vw(-30);
        left: 50%;
        transform: translateX(-50%);
        width: 100%;
        text-align: center;
        font-size: vw(14);
        font-family: Arial;
        font-weight: 400;
        color: rgba(143, 199, 255, 0.6);
        padding-bottom: vh(20);
      }

      .bar {
        width: 100%;
        height: calc(100% - #{vw(56)});
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        align-items: center;

        .list {
          width: vw(32);
          color: #fff;
          position: relative;

          @mixin yuan($color1, $color2, $zindex) {
            &::before {
              content: "";
              display: block;
              width: 100%;
              height: vh(14);
              background: linear-gradient(180deg, $color1 0%, $color2 100%);
              border-radius: 50%;
              position: absolute;
              bottom: vh(-7);
              left: 0;
              z-index: $zindex;
            }

            &::after {
              content: "";
              display: block;
              width: 100%;
              height: vh(14);
              background: linear-gradient(180deg, $color1 0%, $color2 100%);
              border-radius: 50%;
              position: absolute;
              top: vh(-7);
              left: 0;
              z-index: $zindex;
            }
          }

          &:nth-child(4) {
            background: linear-gradient(180deg, #1890ff 0%, #60b2ff 100%);
            position: relative;
            @include yuan(#1890ff, #60b2ff, 1);
          }
          &:nth-child(3) {
            background: linear-gradient(180deg, #3ec4d9 0%, #65eaff 100%);
            position: relative;
            @include yuan(#3ec4d9, #65eaff, 2);
          }
          &:nth-child(2) {
            background: linear-gradient(180deg, #60d83d 0%, #a2f889 100%);
            position: relative;
            @include yuan(#60d83d, #a2f889, 3);
          }
          &:nth-child(1) {
            background: linear-gradient(180deg, #f6c516 0%, #ffe520 100%);
            position: relative;
            @include yuan(#f6c516, #ffe520, 4);
          }

          &_hidden {
            &::before {
              display: none !important;
            }
            &::after {
              display: none !important;
            }
          }
        }
      }

      .title {
        width: 100%;
        text-align: center;
        font-size: vw(14);
        font-family: Microsoft YaHei UI;
        font-weight: 400;
        color: rgba(143, 199, 255, 0.6);
        padding-top: vh(10);
        opacity: 1;
      }

      &:hover {
        background: rgba(255, 255, 255, 0.06);

        .top-txt,
        .title {
          color: #8fc7ff;
        }
      }
    }
  }
}
</style>